package com.itrh.org.controller;

import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import com.itrh.base.annotation.AuthPermission;
import com.itrh.org.domain.Department;
import com.itrh.org.domain.Employee;
import com.itrh.org.query.DepartmentQuery;
import com.itrh.org.query.EmployeeQuery;
import com.itrh.org.service.IEmployeeService;
import com.itrh.org.util.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * ClassName: EmployeeController
 *
 * @author XHU_WHY
 * @version V1.0
 * @since 2024/4/2 16:40
 */
@RestController
@RequestMapping("/emp")
@AuthPermission(name = "员工管理")
public class EmployeeController {

    @Resource
    private IEmployeeService employeeService;

    @PutMapping
    @ApiOperation(value = "通过ID查询")
    @AuthPermission(name = "添加/修改员工")
    public Result saveOrUpdate(@RequestBody Employee employee) {
        return employeeService.saveOrUpdate(employee);
    }

    @GetMapping
    @ApiOperation(value = "查询所有")
    @AuthPermission(name = "查询所有员工")
    public Result list() {
        return employeeService.selectAll();
    }

    @PostMapping
    @ApiOperation(value = "分页查询")
    @AuthPermission(name = "条件分页查询员工")
    public Result pageList(@RequestBody EmployeeQuery query) {
        return employeeService.pageList(query);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @AuthPermission(name = "通过ID查询员工")
    public Result getById(@PathVariable Long id) {
        return employeeService.selectById(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "通过ID删除")
    @AuthPermission(name = "通过ID删除员工")
    public Result deleteById(@PathVariable Long id) {
        return employeeService.deleteById(id);
    }

    @PatchMapping
    @ApiOperation(value = "批量删除")
    @AuthPermission(name = "批量删除员工")
    public Result batchRemove(@RequestBody List<Long> ids) {
        return employeeService.batchRemove(ids);

    }

    @PostMapping("/import")
    @ApiOperation(value = "文件导入员工数据")
    public void importEmployee(MultipartFile file, HttpServletResponse response) throws Exception {
        employeeService.importEmployee(file, response);
    }

    @GetMapping("/export")
    @ApiOperation(value = "文件导出员工数据")
    public void exportEmployee(String name, HttpServletResponse response) throws IOException {
        employeeService.exportEmployee(name, response);
    }
}
